<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
      #a {
        display: none;
      }
      #b {
        visibility: hidden;
      }
    </style>
  </head>
  <body>
    <div id="a">1234</div>
    <div id="b">4567</div>
  </body>

  <script>
    const a = document.getElementById("a");

    a.addEventListener("click", () => {
      console.log("a click now");
    });

    const b = document.getElementById("b");

    b.addEventListener("click", () => {
      console.log("b click now");
    });

    const rate = 0.9;

    const request = () => {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          const res = Math.random();
          if (res > rate) {
            resolve(res);
          }
          reject("network error");
        }, 2000);
      });
    };

    const retry = (fn = () => {}, retryCount = 3, retryTimeOut = 2000) => {
      let count = retryCount;
      const _fn = () => {
        fn()
          .then((res) => {
            console.log("network success", res);
          })
          .catch((e) => {
            console.log(e);
            count--;
            count > 0 &&
              setTimeout(() => {
                console.log("retry now");
                _fn();
              }, retryTimeOut);
          });
      };
      _fn();
    };

    retry(request);
  </script>
</html>
